﻿<Page
    x:Class="DvachBrowser3.Views.ThreadPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DvachBrowser3.Views"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:vm="using:DvachBrowser3.ViewModels"
    xmlns:pa="using:DvachBrowser3.Views.Partial"
    xmlns:behaviors="using:Template10.Behaviors"
    xmlns:ps="using:DvachBrowser3.PageServices"
    xmlns:localBehaviors="using:DvachBrowser3.Behaviors"
    xmlns:controls="using:Template10.Controls"
    xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
    x:Name="ThisPage" KeyDown="ThreadPage_OnKeyDown">

    <ps:PageServices.Services>
        <ps:PageServiceCollection>
            <ps:ShellAppBarPageService />
            <ps:ViewModelLifetimePageService />
            <ps:StoreNavigationDataPageService MinutesToStore="60" Version="1.0.0"/>
        </ps:PageServiceCollection>
    </ps:PageServices.Services>
    
    <Page.Resources>
        <Storyboard x:Key="ShowNewPostsAnimation">
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NewPostsIndicator" Storyboard.TargetProperty="Visibility">
                <DiscreteObjectKeyFrame Value="Visible" KeyTime="0:0:0.0" />
            </ObjectAnimationUsingKeyFrames>
            <DoubleAnimation Storyboard.TargetName="NewPostsIndicator" Storyboard.TargetProperty="Opacity" From="0" To="0.75" Duration="0:0:0.1" />
            <DoubleAnimation Storyboard.TargetName="NewPostsIndicatorTransform" Storyboard.TargetProperty="X" From="32" To="0" Duration="0:0:0.1" />
        </Storyboard>
        <Storyboard x:Key="HideNewPostsAnimation">
            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="NewPostsIndicator" Storyboard.TargetProperty="Visibility">
                <DiscreteObjectKeyFrame Value="Collapsed" KeyTime="0:0:0.1" />
            </ObjectAnimationUsingKeyFrames>
            <DoubleAnimation Storyboard.TargetName="NewPostsIndicator" Storyboard.TargetProperty="Opacity" From="0.75" To="0" Duration="0:0:0.1" />
            <DoubleAnimation Storyboard.TargetName="NewPostsIndicatorTransform" Storyboard.TargetProperty="X" From="0" To="32" Duration="0:0:0.1" />
        </Storyboard>
    </Page.Resources>

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup x:Name="VisualStateGroup">
                <VisualState x:Name="VisualStateNarrow">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource NarrowMinWidth}" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                    </VisualState.Setters>
                </VisualState>
                <VisualState x:Name="VisualStateNormal">
                    <VisualState.StateTriggers>
                        <AdaptiveTrigger MinWindowWidth="{StaticResource NormalMinWidth}" />
                    </VisualState.StateTriggers>
                    <VisualState.Setters>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="100*"/>
        </Grid.RowDefinitions>

        <controls:PageHeader BackButtonVisibility="Collapsed" Frame="{x:Bind Frame, Mode=OneWay}" FontWeight="Bold"
                             Content="ТРЕД">
            <interactivity:Interaction.Behaviors>
                <behaviors:EllipsisBehavior Visibility="Collapsed" />
            </interactivity:Interaction.Behaviors>
        </controls:PageHeader>

        <pa:ProgressIndicatorControl Grid.Row="1" ViewModel="{x:Bind PostCollection.Update.Progress, Mode=OneWay}" ShowMessage="True" />

        <pa:PostCollectionView Grid.Row="2" Margin="4, 4, 4, 0" ViewModel="{x:Bind ViewModel, Mode=OneWay}" MaxLines="20" ShowCounter="True" ShowPreviewSeparator="False" ShowFullPostButton="True"
                               x:Name="MainList" ShowFullPost="MainList_OnShowFullPost" ShowFullScreen="MainList_OnShowFullPost">
        </pa:PostCollectionView>

        <Border x:Name="NewPostsIndicator" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Right" VerticalAlignment="Top" Background="{ThemeResource SystemControlBackgroundAccentBrush}" Opacity="0.75" Padding="4"
                Visibility="Collapsed" Tapped="NewPostsIndicator_OnTapped">
            <Border.RenderTransform>
                <TranslateTransform x:Name="NewPostsIndicatorTransform" />
            </Border.RenderTransform>
            <TextBlock FontWeight="SemiBold" FontSize="{x:Bind StyleManager.Text.TitleFontSize, Mode=OneWay}" Foreground="White">НОВЫЕ ПОСТЫ</TextBlock>
        </Border>

        <pa:ContentPopup Grid.Row="1" Grid.RowSpan="2" x:Name="SinglePostViewPopup" IsContentVisibleChanged="ContentPopup_OnIsContentVisibleChanged">
            <pa:ContentPopup.ViewContent>
                <pa:SinglePostCollectionView ViewModel="{x:Bind ViewModel, Mode=OneWay}" MaxLines="0" ShowCounter="True" ShowPreviewSeparator="False" ShowFullPostButton="False"
                                             x:Name="SingleList" SelectedItem="{x:Bind SingleSelectedItem, Mode=TwoWay}"
                                             BackButtonClick="SingleList_OnBackButtonClick" GoButtonClick="SingleList_OnGoButtonClick"/>
            </pa:ContentPopup.ViewContent>
        </pa:ContentPopup>
    </Grid>
</Page>
